import os
from selenium import webdriver
from selenium.webdriver.edge.service import Service

## 获取当前路径

## 设置保存路径
#获取当前的路径
abs_path = os.path.abspath(__file__)

## 获取log文件夹的路径
# 项目路径
main_path = os.path.dirname(os.path.dirname(abs_path))

drivers_path = os.path.join(main_path,'drivers')

def get_driver(driver_name):
    """
    自动获取驱动，
    :param driver_name: 浏览器名字
    :return:
    """
    driver_name = str(driver_name).lower()
    if driver_name == 'edge':
        ##这里创建驱动
        path = r''+drivers_path+'\\'+'msedgedriver.exe'
        edge_driver = webdriver.Edge(service=Service(path))
        return edge_driver
    elif driver_name == 'chrome':
        # chrome 驱动版本不对需要更改
        path = r'' + drivers_path + '\\' + 'chromedriver.exe'
        chrome_driver = webdriver.Chrome(service=Service(path))
        return chrome_driver
    else:
        print('没有找到对应的驱动')


if __name__ == '__main__':
    driver = get_driver('chrome')

    driver.get('https://www.baidu.com/')
    print(get_driver('chrome'))
